home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
dev
/
misc
/
IOBlixDevKitR2.lha
/
IOBlixDevKit
/
C
/
examples
/
QueryUARTs.c
< prev
Wrap
C/C++ Source or Header
|
1999-01-03
|
3KB
|
75 lines
/*
This program is meant to demonstrate how to get all necessary information
about a specific chip on an IOBlix board and how to program that chip in a
system-friendly manner
*/
#include <exec/exec.h>
#include <resources/ioblix.h>
#include <ioblix/uart.h>
#include <stdio.h>
#include <string.h>
#include <proto/exec.h>
#include <proto/ioblix.h>
UBYTE __aligned myname[]="QueryUARTs 37.1 "__AMIGADATE__;
UBYTE __aligned version[]="$VER: QueryUARTs 37.1 "__AMIGADATE__;
UBYTE __aligned copyright[]="(C)opyright 1998,1999 by Thore Böckelmann and RBM Computertechnik. All rights reserved";
struct IOBlixResource *IOBlixBase = NULL;
void main(void)
{
struct IOBlixChipNode *chipNode;
ULONG board;
ULONG unit;
UBYTE *prevOwner;
struct UART *uart;
IOBlixBase = (struct IOBlixResource *)OpenResource(IOBLIXRESNAME);
if (IOBlixBase) {
for (board = 0; board < IOBLIX_MAX_Z2_BOARDS; board++) {
for (unit = 0; unit < IOBLIX_Z2_NUM_SERUNITS; unit++) {
/* first simply try to find each serial UART */
/* if it is available then print some information */
chipNode = FindChip(ICT_SERIAL_Z2_CHIP, board*10+unit);
if (chipNode) {
printf("UART %ld on board %ld is a \"%s\" with %ld bytes FIFO\n", unit, board, chipNode->icn_Description, chipNode->icns_FIFOSize);
printf("current user: %s\n", (chipNode->icn_Owner) ? chipNode->icn_Owner : (UBYTE *)"nobody");
/* now try to obtain chip for exclusive use */
prevOwner = NULL;
chipNode = ObtainChip(ICT_SERIAL_Z2_CHIP, board*10+unit, myname, &prevOwner);
if (chipNode) {
if (chipNode->icns_UARTType == SCPT_16654) {
uart = (struct UART *)chipNode->icn_Address;
/* now play a bit with the UART's scratch register */
/* every value written to this register should also be read back */
/* else something really bad has happened */
uart->scr = 0x55;
if (uart->scr != 0x55) printf("read failure\n");
uart->scr = 0xaa;
if (uart->scr != 0xaa) printf("read failure\n");
} else {
printf("UART is not a 16C654!\n");
}
/* now release the chip again */
ReleaseChip(chipNode);
} else {
/* ObtainChip() failed, so let's check for other owners */
if (prevOwner) printf("chip is already in use by \"%s\"\n", prevOwner);
}
} else {
printf("UART %ld on board %ld is not available\n", unit, board);
}
}
}
} else {
printf("Can't find ioblix.resource. Please run SetupIOBlix\n");
}
}